<extend name="Public:index" />
<block name="mycss">
</block>
<block name="main-content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-body">
                        <h4 class="mt-0 header-title">消息列表</h4>
                        <p class="text-muted mb-4">
                        </p>
                        <div class="table-responsive">
                            <table class="table mb-0">
                                <tbody>
                                    <volist name="list" id="mlist">
                                    <tr class="border-0">
                                        <td class="border-0" width="5%">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="checkbox_{$mlist.id}" value="{$mlist.id}">
                                                <label class="custom-control-label" for="checkbox_{$mlist.id}"></label>
                                            </div>
                                        </td>
                                        <td class="border-0"><i class="mdi mdi-circle-outline mr-1 text-pink"></i><a href="#" data-toggle="modal" data-target="#showModal" data-id="{$mlist.id}">{$mlist.title}</a></td>
                                        <td class="border-0 status">{$mlist['is_read'] ? '已读' : '未读'}</td>
                                        <td class="border-0">{$mlist.datetime}</td>
                                        <td class="border-0 yaoqing">{$mlist['type_result']==1 ? '接受邀请' : ($mlist['type_result']==-1 ? '拒绝邀请' : '等待')}</td>
                                        <td class="border-0">
                                        <if condition="$mlist[type] eq 1 and $mlist['is_read'] neq 1">
                                            <button type="button" class="btn btn-primary waves-effect waves-light pass" data-id="{$mlist.id}">同意</button>
                                            <button type="button" class="btn btn-danger waves-effect waves-light refuse" data-id="{$mlist.id}">拒绝</button>  
                                        </if>
                                        </td>
                                    </tr>
                                    </volist>
                                    <tr>
                                        <td colspan="6">
                                            <button class="btn btn-danger btn-sm delbtn" type="button"><i class="fa fa-trash-alt"></i> 删除</button>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        <nav  aria-label="...">
                            {$page}
                    
                            <!--end pagination-->
                        </nav>
                        <!--end nav-->
                        <!--table responsive-->
                    </div>
                    <!--end card-body-->
                </div>
                <!--end card-->
            </div> <!-- end col -->
        </div> <!-- end row -->
    </div><!-- container -->
    <div class="modal fade" id="showModal" tabindex="-1" role="dialog" aria-labelledby="showModal" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title" id="ModalTitle">消息查看</h5>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
              
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            </div>
          </div>
        </div>
      </div>
</block>
<block name="myscript">
<script>
    $('#showModal').on('show.bs.modal', function (e) {
        var obj = $(e.relatedTarget);
        var id = obj.data('id');
        var tr = obj.closest('tr');
        var _this = this;
        var url = "{:U('getMsg')}";

        $.get(url, {id: id}, function(res){ 
            $(_this).find('.modal-body').html(res);
        });
        tr.find('.status').text('已读');
    })

    $(document).on('click', '.pass', function(){
        var url = "{:U('accept')}";
        var id = $(this).data('id');
        var tr = $(this).closest('tr');
        var _this = this;
        $.post(url, {id:id}, function(res){
            if(res == '1'){
                notify('success','提示','已接受项目邀请！');
                tr.find('.yaoqing').text('接受邀请');
            }
        });
    });

    $(document).on('click', '.refuse', function(){
        var url = "{:U('refuse')}";
        var id = $(this).data('id');
        var tr = $(this).closest('tr');
         $.post(url, {id:id}, function(res){
            if(res == '1'){
                notify('success','提示','已拒绝项目邀请！');
                tr.find('.yaoqing').text('拒绝邀请');
            }
        });
    });

    $('.delbtn').on('click', function(e){
		e.stopPropagation();
		var chks = $('.custom-control-input:checked');
		var ids = [];
		chks.each(function(i,e){
			ids.push($(this).val());
		});
		if(ids.length > 0){
			var url = "{:U('delMsg')}";
			if(confirm('确定删除选定的消息吗？')){
				$.post(url, {ids: ids}, function(res){
					if(res=='1'){
                        notify('success','提示','消息删除成功！');
						window.location.reload();
					} else {
                        notify('error','提示','消息删除失败！');
					}
				});
			}
		}
	});
</script>
</block>